package org.gp.core.web;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.gp.core.entity.dto.ResponseDTO;
import org.gp.core.entity.result.UserHobbyResult;
import org.gp.core.service.IHobbyService;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 用户表  前端控制器
 * </p>
 *
 * @author LuoLiang
 * @since 2017-01-24
 */
@RestController
@RequestMapping("/hobby")
@Slf4j
public class HobbyController {
    @Resource
    private IHobbyService hobbyService;

    @RequestMapping(value = "updatehobby", method = RequestMethod.POST)
    public String updateHobby(@CookieValue("USERID") Integer userId, String hobby) {
        ResponseDTO dto = hobbyService.updateHobby(userId, hobby);

        return JSON.toJSONString(dto);
    }

    @RequestMapping(value = "gethobby", method = RequestMethod.GET)
    public String getHobbyByUser(@CookieValue("USERID") Integer userId) {
        ResponseDTO<UserHobbyResult> dto = hobbyService.getHobbyByUser(userId);

        return JSON.toJSONString(dto);
    }
}
